﻿<%@ Page Title="Edit Resources &raquo; ResourceBlender.NET" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ResourcesOnline.aspx.cs" Inherits="ResourcesOnline" EnableEventValidation="false" ValidateRequest="false" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<%@ Register TagPrefix="L49" Namespace="Lime49.UI" %>
<%@ Register TagPrefix="L49" TagName="ApplicationSelector" Src="~/ApplicationSelector.ascx" %>

<asp:Content ID="contentHead" ContentPlaceHolderID="head" Runat="Server">
    <link rel="Stylesheet" type="text/css" href="css/spreadsheet.css" />
    <!--[if IE]>
    <link rel="Stylesheet" type="text/css" href="css/ie-spreadsheet.css" />
    <![endif]-->
</asp:Content>
<asp:Content ID="contentMain" ContentPlaceHolderID="cntMain" Runat="Server">
    <asp:ScriptManager ID="scrUpdateLanguages" runat="server">
    </asp:ScriptManager>
    <asp:MultiView ID="mltMain" runat="server" ActiveViewIndex="0">
        <asp:View ID="viwNoApps" runat="server">
            <h1><asp:Label ID="lblManageResourcesHeading" runat="server" Text="Edit Resources"></asp:Label></h1>
            <p>You must <asp:HyperLink ID="lnkAddApplication" runat="server" Text="add an application" NavigateUrl="~/Applications.aspx">add an application</asp:HyperLink> before editing resources.</p>
        </asp:View>
        <asp:View ID="viwSelectResources" runat="server">
            <h1><asp:Label ID="lblSelectResourcesHeading" runat="server" Text="Edit Resources"></asp:Label></h1>
            <div class="breadcrumbs">
                <asp:HyperLink ID="lnkNavHome" runat="server" NavigateUrl="~/Default.aspx">ResourceBlender.NET</asp:HyperLink> &gt; <asp:HyperLink ID="lnkNavResources" runat="server" NavigateUrl="~/Resources.aspx">Resources</asp:HyperLink> &gt; Edit Resources Online
            </div>
            <div class="niceform">
                <L49:ApplicationSelector ID="appSelector" runat="server" />
                <div class="actions">
                    <asp:Button ID="btnEditResources" runat="server" Text="Edit Resources Online" CssClass="uniformbutton doublewidth btnEdit"
                        OnClick="btnEditResources_Click" />
                </div>
            </div>
        </asp:View>
        <asp:View ID="viwManageResources" runat="server">
            <asp:SqlDataSource ID="dsMain" runat="server"
                 ConnectionString="<%$ ConnectionStrings:Default %>"
                 ProviderName="<%$ ConnectionStrings:Default.ProviderName %>"
                 OnSelected="dsMain_Selected">
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="dsBundles" runat="server"
                 ConnectionString="<%$ ConnectionStrings:Default %>"
                 ProviderName="<%$ ConnectionStrings:Default.ProviderName %>"
                 >
            </asp:SqlDataSource>
            <div id="fullsizeholder" class="ssFullSize" runat="server">
                <h1><asp:Label ID="lblEditingResourcesFor" runat="server" Text="formatted text"></asp:Label></h1>
                <div class="breadcrumbs">
                    <asp:HyperLink ID="lnkNavHomeFull" runat="server" NavigateUrl="~/Default.aspx">ResourceBlender.NET</asp:HyperLink> &gt; <asp:HyperLink ID="lnkNavResourcesFull" runat="server" NavigateUrl="~/Resources.aspx">Resources</asp:HyperLink> &gt; <asp:LinkButton ID="lnkNavEditOnline" runat="server" OnClick="lnkNavEditOnline_Click">Edit Resources Online</asp:LinkButton> &gt; <asp:Label ID="lblBreadcrumbEnd" runat="server" Text=""></asp:Label>
                </div>
                <div style="float:left">
                    <asp:UpdateProgress ID="upgGrdResources" runat="server" 
                        AssociatedUpdatePanelID="updGrdResources" 
                        DisplayAfter="100">
                        <ProgressTemplate>
                            <div class="centered"><asp:Image ID="imgLoadingResource" runat="server" ImageUrl="~/images/ajax-loader.gif" AlternateText="Loading..." /></div>
                        </ProgressTemplate>
                    </asp:UpdateProgress>
                </div>
                <div id="inlinenav">
                    <asp:LinkButton ID="lnkExpandScreen" runat="server" CssClass="lnkContract" 
                        OnClientClick="return toggleFullWindow(this);" 
                        OnClick="lnkExpandScreen_Click" CausesValidation="False" 
                        EnableViewState="False">Contract to normal size</asp:LinkButton>
                    <ul>
                        <li class="navApplications" id="lnkApplications"><a id="A1" href="~/Applications.aspx" runat="server" title="Applications">Applications</a></li>
                        <li class="navResources" id="lnkResources"><a id="A2" href="~/Resources.aspx" runat="server" title="Resources">Resources</a></li>
                        <li class="navTemplates"><a id="A3" href="~/Templates.aspx" runat="server" title="Templates">Templates</a></li>
                        <li class="navGenerate" id="lnkGenerate"><a id="A4" href="~/Generate.aspx" runat="server" title="Generate">Generate</a></li>
                        <li class="navImport" id="lnkImport"><a id="A5" href="~/Import.aspx" runat="server" title="Import">Import</a></li>
                        <li class="navHelp"><a href="http://wiki.lime49.com/index.php?title=ResourceBlender" title="Help">Help</a></li>
                        <li class="navBackup" id="lnkBackup"><a id="A6" href="~/Backup.aspx" runat="server" title="Backup &amp; Restore">Backup &amp; Restore</a></li>
                        <li class="navSettings" id="lnkSettings"><a id="A7" href="~/Settings.aspx" runat="server" title="Settings">Settings</a></li>
                    </ul>
                </div>
                <div class="clear"></div>
                <asp:UpdatePanel ID="updGrdResources" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <div class="niceform nicefieldset">
                            <h2><asp:LinkButton ID="lnkToggleFilters" runat="server" ToolTip="Toggle Filters" CausesValidation="false" Text="Filters" OnClick="lnkToggleFilters_Click">
                                <asp:Image ID="imgToggleFilters" runat="server" ToolTip="Toggle Filters" ImageUrl="~/images/arrow_down.gif" />
                            </asp:LinkButton></h2>
                            <asp:Panel ID="pnlFiltersCollapsable" runat="server" CssClass="collapsed">
                                <div class="formrow">
                                    <asp:Label ID="lblBundleFilter" runat="server" Text="Bundle Name" AssociatedControlID="txtBundleFilter" EnableViewState="false"></asp:Label>
                                    <asp:DropDownList ID="cboBundleFilter" runat="server" EnableViewState="false">
                                        <asp:ListItem Text="Contains" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Starts With"></asp:ListItem>
                                        <asp:ListItem Text="Ends With"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:TextBox ID="txtBundleFilter" runat="server" EnableViewState="false"></asp:TextBox>
                                </div>
                                 <div class="formrow">
                                    <asp:Label ID="lblElementFilter" runat="server" Text="Element Name" AssociatedControlID="txtElementFilter"></asp:Label>
                                    <asp:DropDownList ID="cboElementFilter" runat="server">
                                        <asp:ListItem Text="Contains" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Starts With"></asp:ListItem>
                                        <asp:ListItem Text="Ends With"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:TextBox ID="txtElementFilter" runat="server"></asp:TextBox>
                                </div>
                                 <div class="formrow">
                                    <asp:Label ID="lblElementCommentFilter" runat="server" Text="Element Comment" AssociatedControlID="txtElementCommentFilter"></asp:Label>
                                    <asp:DropDownList ID="cboElementCommentFilter" runat="server">
                                        <asp:ListItem Text="Contains" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Starts With"></asp:ListItem>
                                        <asp:ListItem Text="Ends With"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:TextBox ID="txtElementCommentFilter" runat="server"></asp:TextBox>
                                </div>
                                 <div class="formrow">
                                    <asp:Label ID="lblResourceCommentFilter" runat="server" Text="Resource Comment" AssociatedControlID="txtResourceCommentFilter"></asp:Label>
                                    <asp:DropDownList ID="cboResourceCommentFilter" runat="server">
                                        <asp:ListItem Text="Contains" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Starts With"></asp:ListItem>
                                        <asp:ListItem Text="Ends With"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:TextBox ID="txtResourceCommentFilter" runat="server"></asp:TextBox>
                                </div>
                                 <div class="formrow">
                                    <asp:Label ID="lblTranslationFilter" runat="server" Text="Translation for" AssociatedControlID="txtTranslationFilter"></asp:Label>
                                    <asp:DropDownList ID="cboTranslationFilterLanguage" runat="server">
                                        <asp:ListItem Text="Select Language" Selected="True"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:DropDownList ID="cboTranslationFilter" runat="server">
                                        <asp:ListItem Text="Contains" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Starts With"></asp:ListItem>
                                        <asp:ListItem Text="Ends With"></asp:ListItem>
                                        <asp:ListItem Text="Is Blank"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:TextBox ID="txtTranslationFilter" runat="server"></asp:TextBox>
                                </div>
                                <div class="formrow block actions">
                                    <asp:Button ID="btnApplyFilters" runat="server" Text="Apply Filters" 
                                        CssClass="uniformbutton btnFilter" EnableViewState="False" 
                                        OnClick="btnApplyFilters_Click" ValidationGroup="filters" />
                                    <asp:Button ID="btnRemoveFilters" runat="server" Text="Remove Filters" 
                                        CssClass="uniformbutton btnUnfilter" EnableViewState="False" 
                                        OnClick="btnRemoveFilters_Click" ValidationGroup="filters" />
                                </div>
                            </asp:Panel>
                        </div><!-- filters form -->
                        <L49:BetterGridView ID="grdResources" runat="server" AllowPaging="True" 
                            AllowSorting="True" AutoGenerateColumns="true" CssClass="nicetable"
                            DataSourceID="dsMain"
                            Width="100%" DataKeyNames="applicationid,bundlename,elementname"
                            OnRowCommand="grd_RowCommand" 
                            OnRowDatabound="grd_RowDataBound"
                            OnPageIndexChanging="grd_PageIndexChanging"
                            OnPreRender="grd_PreRender"
                            OnSorting="grd_Sorting"
                            PageSize="15">
                            <PagerSettings PageButtonCount="8" Mode="NumericFirstLast" Position="TopAndBottom" />
                            <HeaderStyle CssClass="excelHead" />
                            <RowStyle CssClass="even" />
                            <AlternatingRowStyle CssClass="alt" />
                            <PagerStyle CssClass="pager" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <%# Container.DataItemIndex +1 %>
                                    </ItemTemplate>
                                    <ItemStyle CssClass="ssRowLabel" HorizontalAlign="Center" />
                                </asp:TemplateField>
                                <asp:TemplateField SortExpression="bundlename" HeaderText="Bundle">
                                    <ItemTemplate>
                                        <asp:MultiView ID="mltBundle" runat="server" ActiveViewIndex="0">
                                            <asp:View ID="viwShowBundle" runat="server">
                                                <asp:Label ID="lblBundleName" runat="server" Text='<%# Eval("bundlename") %>'></asp:Label>
                                            </asp:View>
                                            <asp:View ID="viwEditBundle" runat="server">
                                                <asp:DropDownList ID="cboBundleName"  runat="server" ValidationGroup="editelement" DataSourceID="dsBundles" DataTextField="name" DataValueField="id"></asp:DropDownList>
                                            </asp:View>
                                        </asp:MultiView>
                                    </ItemTemplate>
                                    <ItemStyle CssClass="ssCell" />
                                </asp:TemplateField>
                                <asp:TemplateField SortExpression="elementname" HeaderText="Element">
                                    <ItemTemplate>
                                        <asp:MultiView ID="mltElement" runat="server" ActiveViewIndex="0">
                                            <asp:View ID="viwShowElement" runat="server">
                                                <asp:Label ID="lblElementName" runat="server" Text='<%# Utils.TrimText(Eval("elementname").ToString(), 30) %>'></asp:Label>
                                            </asp:View>
                                            <asp:View ID="viwEditElement" runat="server">
                                                <asp:Label ID="lblElementNameDesc" runat="server" Text="Element Name" AssociatedControlID="txtElementName" EnableViewState="False" CssClass="block"></asp:Label>
                                                <asp:TextBox ID="txtElementName" runat="server" Text='<%# Eval("elementname") %>' EnableViewState="False" ValidationGroup="editelement" CssClass="block"></asp:TextBox>
                                                <asp:Label ID="lblElementComment" runat="server" Text="Comment" AssociatedControlID="txtElementComment" EnableViewState="False" CssClass="block"></asp:Label>
                                                <asp:TextBox ID="txtElementComment" runat="server" Text='<%# Eval("elementcomment") %>' TextMode="MultiLine" EnableViewState="False" ValidationGroup="editelement" CssClass="block"></asp:TextBox>
                                                <asp:HyperLink ID="btnEditPO" runat="server" 
                                                        Text='<%# "Show the PO editor for element #" + Eval("id") %>' 
                                                        ToolTip='<%# "Show the PO editor for element #" + Eval("id") %>' 
                                                        NavigateUrl="#"
                                                        CssClass="btnPOEdit" />
                                                <asp:RequiredFieldValidator SetFocusOnError="true" Display="Dynamic" ID="vldEditElementName" runat="server" 
                                                    ErrorMessage="Element name must be entered" ControlToValidate="txtElementName" ValidationGroup="editelement"></asp:RequiredFieldValidator>
                                            </asp:View>
                                        </asp:MultiView>
                                    </ItemTemplate>
                                    <ItemStyle CssClass="ssCell" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Commands">
                                    <ItemTemplate>
                                        <asp:MultiView ID="mltActions" runat="server" ActiveViewIndex="0">
                                            <asp:View ID="viwEdit" runat="server">
                                                <div class="centered">
                                                    <asp:ImageButton ID="btnEdit" runat="server" 
                                                        AlternateText='<%# "Edit " + Eval("elementname") %>' 
                                                        ToolTip='<%# "Edit " + Eval("elementname") %>' 
                                                        EnableViewState="False"
                                                        CommandName="editresource" 
                                                        ImageUrl="~/images/edit.png" />
                                                    <asp:ImageButton ID="btnDelete" runat="server" 
                                                        ToolTip='<%# "Delete element #" + Eval("id") %>' 
                                                        CommandName="deleteelement" 
                                                        CommandArgument='<%# Eval("id") %>'
                                                        ImageUrl="~/images/delete.png" />
                                                </div>
                                            </asp:View>
                                            <asp:View ID="viwSave" runat="server">
                                                <asp:Label ID="lblResourceIdDesc" runat="server" Text="Resource ID" EnableViewState="False" AssociatedControlID="cboResourceID" CssClass="block"></asp:Label>
                                                <asp:DropDownList ID="cboResourceID" runat="server" ValidationGroup="editelement" CssClass="block">
                                                </asp:DropDownList>
                                                <asp:Button ID="btnChangeResource"  Visible="false" runat="server" Text="Change Resource" CommandName="changeresource" EnableViewState="False" />
                                                <asp:Label ID="lblResourceComment" runat="server" Text="Comment" AssociatedControlID="txtResourceComment" EnableViewState="False" CssClass="block"></asp:Label>
                                                <asp:TextBox ID="txtResourceComment" runat="server" Text='<%# Eval("resourcecomment") %>' TextMode="MultiLine" EnableViewState="False" ValidationGroup="editelement" CssClass="block"></asp:TextBox>
                                                <asp:Label ID="lblError" runat="server" Text="" CssClass="block error"></asp:Label>
                                                <asp:Button ID="btnDeleteElement" runat="server" Text="Delete Element" CommandName="deleteelement" CommandArgument='<%# Eval("id") %>' ValidationGroup="editelement" CssClass="block uniformbutton btnDelete doublewidth" />
                                                <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="saveresource" CommandArgument='<%# Eval("id") %>' ValidationGroup="editelement" ToolTip='<%# "Save resource and assign to "+Eval("elementname") %>' CssClass="uniformbutton btnSave" />
                                                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="canceledit" ValidationGroup="editresource" CssClass="uniformbutton btnCancel" />
                                            </asp:View>
                                            <asp:View ID="viwConfirmDelete" runat="server">
                                            <div class="centered">
                                                <asp:Label ID="lblConfirmDelete" runat="server" Text='<%# "Really delete element "+Eval("elementname") + "?" %>' CssClass="block"></asp:Label>
                                                <asp:Button ID="btnConfirmDelete" runat="server" Text="Delete" CommandName="confirmdelete" CommandArgument='<%# Eval("id") %>' ValidationGroup="deleteresource" CssClass="uniformbutton btnConfirm" />
                                                <asp:Button ID="btnCancelDelete" runat="server" Text="Cancel" CommandName="canceledit" ValidationGroup="deleteresource" CssClass="uniformbutton btnCancel" />
                                            </div>
                                        </asp:View>
                                        </asp:MultiView>
                                    </ItemTemplate>
                                    <ItemStyle CssClass="ssCell" />
                                </asp:TemplateField>
                            </Columns>
                        </L49:BetterGridView>
                        <asp:Label ID="lblNoMatching" runat="server" Text="No matching elements" CssClass="noElements"></asp:Label>
                        <div class="niceform nicefieldset">
                            <h2>Add Element</h2>
                            <fieldset>
                                <legend>Element</legend>
                                <div class="formrow block">
                                    <asp:Label ID="lblAddBundleName" runat="server" AssociatedControlID="cboAddBundleName" 
                                        Text="Bundle Name"></asp:Label>
                                    <asp:DropDownList ID="cboAddBundleName" runat="server" ValidationGroup="addelement" DataSourceID="dsBundles" DataTextField="name" DataValueField="id">
                                    </asp:DropDownList>
                                </div>
                                <div class="formrow block">
                                    <asp:Label ID="lblAddElementName" runat="server" AssociatedControlID="txtAddElementName"
                                        Text="Element Name"></asp:Label>
                                    <asp:TextBox ID="txtAddElementName" runat="server" EnableViewState="false" ValidationGroup="addelement"></asp:TextBox>
                                    <asp:Label ID="lblAddError" runat="server" CssClass="error" Visible="false"></asp:Label>
                                    <asp:RequiredFieldValidator SetFocusOnError="true"
                                        ID="vldAddElementName" runat="server" ErrorMessage="Element name must be entered" ControlToValidate="txtAddElementName" ValidationGroup="addelement"></asp:RequiredFieldValidator>
                                </div>
                                <div class="formrow block">
                                    <asp:Label ID="lblAddElementComment" runat="server" Text="Element Comment" ToolTip="Notes about the element's location"  AssociatedControlID="txtAddElementComment" EnableViewState="False"></asp:Label>
                                    <asp:TextBox ID="txtAddElementComment" runat="server" TextMode="MultiLine" ValidationGroup="addelement" CssClass="floatLeft" ></asp:TextBox>
                                    <asp:HyperLink ID="btnAddEditPO" runat="server" 
                                        Text="Show the PO editor"
                                        ToolTip="Show the PO editor"
                                        NavigateUrl="#"
                                        CssClass="btnPOEdit" />
                                </div>
                            </fieldset>
                            <asp:Panel ID="pnlAddedElement" runat="server" Visible="false" CssClass="successDiv">
                                <asp:Literal ID="litAddedElement" runat="server"></asp:Literal>
                            </asp:Panel>
                            <fieldset>
                                <legend>Resource</legend>
                                <div class="formrow block">
                                    <asp:Label ID="lblAddResourceID" runat="server" Text="Resource ID" AssociatedControlID="cboAddResourceID" EnableViewState="False"></asp:Label>
                                    <asp:DropDownList ID="cboAddResourceId" runat="server" AutoPostBack="true"
                                        OnSelectedIndexChanged="ChangeAddDisplayedResource" ValidationGroup="addelement">
                                    </asp:DropDownList>
                                </div>
                                <div class="formrow block">
                                    <asp:Label ID="lblAddResourceComment" runat="server" Text="Resource Comment" ToolTip="Contextual information about the resource" AssociatedControlID="txtAddResourceComment" EnableViewState="False"></asp:Label>
                                    <asp:TextBox ID="txtAddResourceComment" runat="server" TextMode="MultiLine" EnableViewState="False" ValidationGroup="addelement"></asp:TextBox>
                                </div>
                                <asp:table id="tblAddResource" CssClass="addresource" runat="server">
                                    <asp:TableHeaderRow Visible="false">
                                        <asp:TableHeaderCell>Language</asp:TableHeaderCell>
                                        <asp:TableHeaderCell>Resource</asp:TableHeaderCell>
                                        <asp:TableHeaderCell>Actions</asp:TableHeaderCell>
                                    </asp:TableHeaderRow>
                                </asp:table>
                                <div class="formrow block actions">
                                    <asp:Button ID="btnAddElement" runat="server" Text="Add Element" 
                                        CssClass="uniformbutton btnAdd" EnableViewState="False" 
                                        OnClick="btnAddElement_Click" ValidationGroup="addelement" />
                                </div>
                            </fieldset>
                        </div><!--add form-->
                    </ContentTemplate>
                </asp:UpdatePanel>
                <div id="loadingMessage" style="display: none;">
                    <h1>Please Wait...</h1>
                    <img src="images/ajax-loader.gif" alt="" />
                    <small>Not responding? <a id="notResponding" href="#">Click here to close</a>.</small>
                </div>
                <div id="poedit" class="niceform">
                    <h2>Edit PO Data</h2>
                    <p>Enter each comment, reference and flag on a new line. Formatting for <a href="http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files">GNU PO files</a> will be added automatically</p>
                    <div class="formrow block">
                        <label for="txtSrcComments">Source Comments</label>
                        <textarea id="txtSrcComments" rows="5" cols="40"></textarea>
                    </div>
                    
                    <div class="formrow block">
                        <label for="txtReferences">References</label>
                        <textarea id="txtReferences" rows="5" cols="40"></textarea>
                    </div>
                    
                    <div class="formrow block">
                        <label for="txtFlags">Flags</label>
                        <textarea id="txtFlags" rows="5" cols="40"></textarea>
                    </div>
                    
                    <div class="formrow block">
                        <label for="txtContext">Context</label>
                        <textarea id="txtContext" rows="3" cols="40"></textarea>
                    </div>
                    
                    <div class="actions">
                        <asp:Button ID="btnSavePO" runat="server" Text="Save" 
                            CssClass="uniformbutton btnSave" EnableViewState="False" 
                            ValidationGroup="editPO" />
                        <asp:Button ID="btnCancelPO" runat="server" Text="Cancel" 
                            CssClass="uniformbutton btnCancel" EnableViewState="False" 
                            ValidationGroup="editPO" />
                    </div>
                </div>
            </div><!--fullsizeholder-->
        </asp:View>
    </asp:MultiView>
</asp:Content>

